<template>
  <div class="forum-info">
    <headers></headers>
    
    <div class="main-content">
      <!-- 文章标题 -->
      <div class="article-header">
        <h1 class="article-title">{{info.name}}</h1>
      </div>

      <!-- 文章内容 -->
      <div class="article-content">
        <div class="content-body" v-html="info.content"></div>
      </div>
    </div>

    <bottoms></bottoms>
  </div>
</template>

<script>
import {getSysForumById} from '../../api/api'
import headers from '@/components/header'
import bottoms from '@/components/bottom'
export default {
  name: 'ForumInfo',
  components: {
    headers,
    bottoms
  },
  data() {
    return {
      id: "",
      info: {
        content: "",
        name: ""
      }
    }
  },
  methods: {
    getSysForumById() {
      getSysForumById({id: this.id}).then(res => {
        if (res.code == 1000) {
          this.info = {
            ...res.data,
            content: this.cleanContent(res.data.content)
          }
        }
      })
    },
    cleanContent(content) {
      if (!content) return '';
      // 移除开头的<p>和结尾的</p>标签
      return content.replace(/^<p>|<p class="[^"]*">|<\/p>$/g, '')
        // 移除多余的<strong>标签
        .replace(/<\/?strong>/g, '')
        // 移除&nbsp;
        .replace(/&nbsp;/g, ' ')
        // 移除多余的空格
        .replace(/\s+/g, ' ')
        .trim();
    }
  },
  mounted() {
    this.id = this.$route.query.id
    this.getSysForumById()
  }
}
</script>

<style scoped>
.forum-info {
  background-color: #ffffff;
  min-height: 100vh;
}

.main-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 60px 20px;
}

/* 文章标题样式 */
.article-header {
  margin-bottom: 50px;
  text-align: center;
}

.article-title {
  font-size: 42px;
  font-weight: 700;
  color: #2c3e50;
  line-height: 1.4;
  letter-spacing: -0.5px;
  position: relative;
  padding-bottom: 30px;
}

.article-title:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 4px;
  background: #3498db;
  border-radius: 2px;
}

/* 文章内容样式 */
.article-content {
  margin-bottom: 60px;
}

.content-body {
  color: #2c3e50;
  line-height: 1.8;
  font-size: 17px;
}

.content-body :deep(p) {
  margin: 1.8em 0;
}

.content-body :deep(img) {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 2em 0;
}

.content-body :deep(h1),
.content-body :deep(h2),
.content-body :deep(h3) {
  margin: 2em 0 1em;
  color: #2c3e50;
  font-weight: 700;
}

/* 响应式布局 */
@media (max-width: 768px) {
  .main-content {
    padding: 40px 20px;
  }

  .article-title {
    font-size: 32px;
    padding-bottom: 20px;
  }

  .content-body {
    font-size: 16px;
  }
}
</style>